package cn.com.self.apis.portal.controller;

import cn.com.self.apis.portal.entity.ClassificationEntity;
import cn.com.self.apis.portal.mapper.ClassificationMapper;
import cn.com.self.apis.portal.service.intf.IClassificationService;
import cn.com.self.apis.util.CopyUtils;
import cn.com.selfsoft.smartcity.commons.http.DataItem;
import cn.com.selfsoft.smartcity.commons.http.DataPage;
import cn.com.selfsoft.smartcity.commons.http.ResultModel;
import cn.com.selfsoft.smartcity.commons.util.ParameterUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author CRL
 * @date 2021/1/9 16:23
 */
@Controller
@RequestMapping("/classification")
@Api(tags = "行业分类")
public class ClassificationController {

    @Autowired
    IClassificationService classificationService;

    @PostMapping(value = "/create")
    @ApiOperation(value = "创建行业分类")
    public ResponseEntity create(@RequestBody ClassificationEntity entity) {
        return classificationService.creat(entity);
    }

    @DeleteMapping(value = "/delete/{id}")
    @ApiOperation(value = "删除行业分类")
    public ResponseEntity deletes(@PathVariable("id") String id) {
        return classificationService.deleteClassification(id);
    }

    @PostMapping(value = "/update/{id}")
    @ApiOperation(value = "更新行业分类")
    public ResponseEntity update(@PathVariable("id") String id, @RequestBody ClassificationEntity entity) {
        return classificationService.updateClassification(id,entity);

    }

    @GetMapping(value = "/page")
    @ApiOperation(value = "分页获取行业分类")
    public ResponseEntity getUserPage(HttpServletRequest request, Pageable page) {
        Map<String, Object> queryParams = ParameterUtil.HumpToUnderline(request.getParameterMap(), "mark", "size", "page", "sort", "access_token");
        return classificationService.getUserPage(queryParams,page);
    }

    @GetMapping(value = {"/load/{id}"})
    @ApiOperation(value = "根据id获取数据")
    public ResponseEntity loadId(@PathVariable("id") String id, HttpServletRequest request) {
        return classificationService.loadId(id);
    }

}
